package com.cwg.dict.stem.model;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.ToStringBuilder;

/**
 * A <code>Token</code> is the basic element of a word, a word can be slit to one or more token.
 * for example the word 'atypical' is combine by 3 tokens, a / typ / ical, 'a' is a <code>Prefix</code> token,
 *  'typ' is a stem token, 'ical' is a suffix token.
 * @author kent
 *
 */
@XmlAccessorType(XmlAccessType.FIELD)
public class Token {

	@XmlAttribute(name = "description")
	private String	description;

	private Group	group;

	@XmlAttribute(name = "name")
	private String	name;

	@XmlAttribute(name = "original")
	private String	original;

	@XmlAttribute(name = "translate")
	private String	translate;

	public Token() {
		super();
	}

	public Token(String source) {
		name = source;
	}

	public String getDescription() {
		return description;
	}

	public Group getGroup() {
		return group;
	}

	public String getName() {
		return name;
	}

	public String getOriginal() {
		return original;
	}

	public String getTranslate() {
		return translate;
	}

	/**
	 * when the source is as same as original that means <code>Token</code> is not a really token but basic word.
	 * for example:
	 * <code>
	 * token.getSource() == "is";
	 * token.getOriginal() == "is";
	 * </code> 
	 * the word 'is' is not listed in Token list and can't be split to token(atomic). 
	 * @return true the source is basic word, can't split to any token.
	 *  false the source a token.
	 */
	public boolean isBasicWord() {
		// source == original means not a token but basic word
		return StringUtils.equalsIgnoreCase(getName(), getOriginal());
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public void setGroup(Group group) {
		this.group = group;
	}

	public void setName(String soruce) {
		this.name = soruce;
	}

	public void setOriginal(String original) {
		this.original = original;
	}

	public void setTranslate(String translate) {
		this.translate = translate;
	}

	@Override
	public String toString() {
		ToStringBuilder result = new ToStringBuilder(this);
		return result.append("name", name).append("original", original).append("translate", translate).toString() + "\n";

	}

}
